package com.hlhj.carview.aty

import android.support.v7.widget.LinearLayoutManager
import com.example.mymvp.mvp.BaseModule
import com.example.mymvp.mvp.BasePresenter
import com.example.mymvp.mvp.BaseView
import com.hlhj.carview.BaseAty
import com.hlhj.carview.R
import com.hlhj.carview.adapter.MyAskListAdp
import com.hlhj.carview.bean.ItemAskListBean
import com.hlhj.carview.bean.MyAskListBean
import com.hlhj.carview.http.CustomAction
import com.hlhj.carview.http.MyJsonConvert
import com.hlhj.carview.http.Urls
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableResponse
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.aty_myask.*
import kotlinx.android.synthetic.main.lo_pubhead.*

/**
 *NeverMore
 *2020/9/10
 **/
class MyAskListAty:BaseAty<BaseView,BasePresenter<BaseModule,BaseView>>(), BaseView {
    private val datas=ArrayList<MyAskListBean.Data>()
    private lateinit var adp:MyAskListAdp

    override fun initView() {
        tvTittle.text="已接受的委托"
        adp= MyAskListAdp(datas)
        listView.adapter=adp
        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)

    }


    override fun logicStart() {
        val httpParams = HttpParams()
        httpParams.put("uriPath","itemAskList")
        OkGo.post<MyAskListBean>(Urls.PubUrl)
                .headers("type",3.toString())
                .params(httpParams)
                .converter(object : MyJsonConvert<MyAskListBean>(){})
                .adapt(ObservableResponse<MyAskListBean>())
                .subscribeOn(Schedulers.io())
                .subscribe(object : CustomAction<Response<MyAskListBean>>(this){
                    override fun httpSuccess(t: Response<MyAskListBean>) {
                        t.body().data?.let { it1 -> datas.addAll(it1) }
                        adp.notifyDataSetChanged()
                    }
                })

    }

    override fun setListener() {
    }

    override fun getContentID(): Int {
        return R.layout.aty_myask
    }

    override fun bindView(): BaseView {
        return this
    }

    override fun createPresenter(): BasePresenter<BaseModule, BaseView> {
        return object :BasePresenter<BaseModule,BaseView>(){
            override fun createModule() {
                module=object :BaseModule{

                }
            }
        }
    }
}